home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / admin / linuxcon.000 / linuxcon / linuxconf-1.6 / dialog / term.c < prev    next >
C/C++ Source or Header  |  1996-08-01  |  3KB  |  115 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include "diadef.h"
  4. #include "dialog.h"
  5. #include "internal.h"
  6.  
  7. PRIVATE void DIALOG::showtimeout(WINDOW *win)
  8. {
  9.     int t = dialog_getcurtimeout();
  10.     if (t > 0){
  11.         wmove(win, height-1,width-6);
  12.         wattrset(win, dialog_attr);
  13.         char buf[10];
  14.         sprintf (buf,"%3d ",t);
  15.         waddstr (win,buf);
  16.     }
  17. }
  18.  
  19. PRIVATE MENU_STATUS DIALOG::editterm(
  20.     int &nof,
  21.     int but_options)
  22. {
  23.     MENU_STATUS ret = MENU_NULL;
  24.     WINDOW *dialog = dialog_openwin (height,width);
  25.     if (nof >= getnb()) nof = getnb()-1;
  26.     if (nof < 0) nof = 0;
  27.     if (nof < offset){
  28.         setoffset (nof);
  29.     }else if (nof >= offset + nbvisible){
  30.         int newoff = nof;
  31.         if (newoff + nbvisible > getnb()){
  32.             newoff = getnb() - nbvisible;
  33.         }
  34.         setoffset (newoff);
  35.     }
  36.     draw(dialog);
  37.     dialog_starttimeout();
  38.     showtimeout(dialog);
  39.     int last_nof = nof;
  40.     bool arrow_up = false;
  41.     bool arrow_down = false;
  42.     while (ret == MENU_NULL) {
  43.         drawarrow_if (dialog,offset>0,arrow_up,true,ACS_UARROW);
  44.         drawarrow_if (dialog,offset+nbvisible<getnb()
  45.             ,arrow_down,false,ACS_DARROW);
  46.         if (button == -1){
  47.             if (last_nof != nof
  48.                 && last_nof >= offset
  49.                 && last_nof < offset + nbvisible){
  50.                 getitem(last_nof)->unselect(dialog);
  51.             }
  52.             if (nof >= 0 && nof < getnb()){
  53.                 getitem(nof)->setcursor (dialog);
  54.             }
  55.             last_nof = nof;
  56.         }
  57.         int key = dialog_wgetch(dialog,ret);
  58.         /* #Specification: F3 key / escape
  59.             F3 was not used in Linuxconf and some people claims it
  60.             is fairly common as an equivalent for the escape key.
  61.             So linuxconf support both! Comments are welcome.
  62.         */
  63.         if (key == ESC || key == KEY_F(3)){
  64.             ret = MENU_ESCAPE;
  65.             break;
  66.         }else if (ret == MENU_INTERNAL_TIMEOUT){
  67.             // Update the timeout counter at the bottom
  68.             showtimeout(dialog);
  69.             ret = MENU_NULL;
  70.         }else if (ret != MENU_NULL){
  71.             break;
  72.         }else if (button != -1 || key == KEY_F(1)){
  73.             ret = buttons->dokey (dialog,key,button,getnb()>0);
  74.         }else if (keymove(dialog,key,nof)==-1){
  75.             switch (key) {
  76.             case TAB:
  77.                 button = 0;
  78.                 buttons->draw(dialog,button);
  79.                 break;
  80.             case '\n':
  81.                 if (but_options & MENUBUT_OK){
  82.                     ret = MENU_OK;
  83.                 }else if (getnb()==1){
  84.                     /* #Specification: dialogue / single field case
  85.                         A <enter> in a dialogue with a single
  86.                         field exit as the first button
  87.                         was selected (Generally <Accept>)
  88.                         
  89.                         If the dialog contain a <Ok> button
  90.                         it does the same whatever the number
  91.                         of fields. This is a special case for
  92.                         menu dialog.
  93.                     */
  94.                     button = 0;
  95.                     ret = buttons->dokey (dialog,key,button,1);
  96.                 }else{
  97.                     keymove (dialog,KEY_DOWN,nof);
  98.                 }
  99.                 break;
  100.             default:
  101.                 {
  102.                     FIELD_MSG msg;
  103.                     getitem(nof)->dokey (dialog,key,msg);
  104.                     if (msg.is_loaded) processmsg(dialog,msg);
  105.                 }
  106.             }
  107.         }
  108.     }
  109.     attr_clear(stdscr, LINES, COLS, screen_attr);
  110.     wnoutrefresh(stdscr);
  111.     delwin(dialog);
  112.     return ret;
  113. }
  114.  
  115.